package com.example.springbootblog.mapper;



import com.example.springbootblog.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    /**
     * 获取博客列表
     */
    @Select("select blog_id,title,content,create_time,user_id from bloginfo where delete_flag = 0 order by create_time desc")
    List<BlogInfo> getBlogList();


    /**
     * 根据博客 id 获取博客详情
     */
    @Select("select * from bloginfo where blog_id = #{blogId} and delete_flag = 0")
    BlogInfo getBlogById(Integer blogId);
    /**
     * 根据博客 id 编辑博客
     */

//    @Update("update bloginfo " +
//            "<set>" +
//                "<if text='title != null' " +
//                     " title = #{title}," +
//                "</if>" +
//                "<if text='content != null'>" +
//                     "content = #{content} " +
//                "</if>" +
//            "</set>" +
//            "where blog_id = #{blogId}")
    Integer updateBlog(BlogInfo blogInfo);
    /**
     * 根据博客id 删除博客
     */

    @Update("update bloginfo set delete_flag = 1 where blog_id = #{blogId}")
    Integer deleteBlogById(Integer blogId);
    /**
     * 根据输入内容,添加博客
     */
    @Insert("insert into bloginfo (title,content,user_id) values (#{title},#{content},#{userId})")
    Integer inserBlog(BlogInfo blogInfo);
}
